##  基础函数库
import numpy as np
import pandas as pd
from sklearn import metrics
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

df = pd.read_csv('../../doc/promotion/aicampml/happiness_train_complete.csv',encoding="unicode_escape")
df = df.fillna(-1)
y = df.happiness
x = df.drop(["id","happiness","survey_time","edu_other","property_other","invest_other"],axis=1)
## 为了正确评估模型性能，将数据划分为训练集和测试集，并在训练集上训练模型，在测试集上验证模型性能。
data_target_part = y
data_features_part = x
## 测试集大小为20%， 80%/20%分
x_train, x_test, y_train, y_test = train_test_split(data_features_part, data_target_part, test_size = 0.2)

#The “lbfgs” solver is used by default for its robustness. For large datasets the “saga” solver is usually faster.
clf = LogisticRegression(random_state=2020, solver='saga',max_iter=1000)
clf.fit(x_train, y_train)
## 在训练集和测试集上分布利用训练好的模型进行预测
train_predict = clf.predict(x_train)
test_predict = clf.predict(x_test)
## 利用accuracy（准确度）【预测正确的样本数目占总预测样本数目的比例】评估模型效果
print('The accuracy of the Logistic Regression is:',metrics.accuracy_score(y_train,train_predict))
print('The accuracy of the Logistic Regression is:',metrics.accuracy_score(y_test,test_predict))

if __name__ == '__main__':
    pass